package gases.as3.librarys.core.utils
{
	import flash.utils.Dictionary;

	public class KeyBoardUtil
	{
		public function KeyBoardUtil()
		{
			_keyDict = new Dictionary();
			_charDict = new Dictionary();
			
			registerAllKeys();
		}
		
		public function getCharCode(key:uint):String
		{
			return _keyDict[key] as String;
		}
		
		public function getKeyCode(charCode:String):uint
		{
			return _charDict[charCode] as uint;
		}
		
		private function registerAllKeys():void
		{
			registerKey(65, "A");
			registerKey(66, "B");
			registerKey(67, "C");
			registerKey(68, "D");
			registerKey(69, "E");
			registerKey(70, "F");
			registerKey(71, "G");
			registerKey(72, "H");
			registerKey(73, "I");
			registerKey(74, "J");
			registerKey(75, "K");
			registerKey(76, "L");
			registerKey(77, "M");
			registerKey(78, "N");
			registerKey(79, "O");
			registerKey(80, "P");
			registerKey(81, "Q");
			registerKey(82, "R");
			registerKey(83, "S");
			registerKey(84, "T");
			registerKey(85, "U");
			registerKey(86, "V");
			registerKey(87, "W");
			registerKey(88, "X");
			registerKey(89, "Y");
			registerKey(90, "Z");
			registerKey(13, "ENTER");
			registerKey(9, "TAB");
			registerKey(192, "~");
			registerKey(219, "[");
			registerKey(48, "0");
			registerKey(49, "1");
			registerKey(50, "2");
			registerKey(51, "3");
			registerKey(52, "4");
			registerKey(53, "5");
			registerKey(54, "6");
			registerKey(55, "7");
			registerKey(56, "8");
			registerKey(57, "9");
			registerKey(16,"SHIFT");
		}
		
		private function registerKey(key:uint, charCode:String):void
		{
			_keyDict[key] = charCode;
			_charDict[charCode] = key;
		}
		
		
		public function dispose():void
		{
			_charDict = null;
			_keyDict = null;
		}
		
		private var _charDict:Dictionary;
		private var _keyDict:Dictionary;
	}
}